﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PostSharp4ViewState.Tests
{
   public class Properties : BaseControl
   {
      private int _intValue;

      [Persist(Mode = PersistMode.ViewState)]
      public string StringAutoProp { get; set; }

      [Persist(Mode = PersistMode.ControlState)]
      public int IntProp
      {
         get { return _intValue; }
         set { _intValue = value; }
      }
   }
   [TestClass]
   public class PropertiesTests
   {     
      [TestMethod]
      public void PropertyHandlingWorks()
      {
         Properties props = new Properties();
         props.IntProp = 6;
         props.StringAutoProp = "value";
         object controlState = props.DoSaveControlState();
         object viewState = props.DoSaveViewState();
         Properties readProps = new Properties();
         readProps.DoLoadControlState(controlState);
         readProps.DoLoadViewState(viewState);
         Assert.AreEqual(props.IntProp, readProps.IntProp);
         Assert.AreEqual(props.StringAutoProp, readProps.StringAutoProp);
      }
   }
}
